package hrx.dao;


import hrx.entity.Relation;
import hrx.entity.User;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface RelationDao extends JpaRepository<Relation, Integer> {

    @Query(value = "SELECT * FROM user_task_relation WHERE user_id = ?1 AND task_id = ?2",
            nativeQuery = true)
    Relation findByUserAndTask(Integer userId, Integer taskId);

    @Query(value = "SELECT * FROM user_task_relation WHERE user_id= ?",
            nativeQuery = true)
    List<Relation> findByUser_idRelation(Integer userId);

    @Query(value = "SELECT * FROM user_task_relation WHERE admin_id= ? and task_id=?",
            nativeQuery = true)
    Relation findByAdmin_idAndTask_id(Integer adminId, Integer taskId);

    /**
     * 根据任务id查找关系
     * @param taskId
     * @return
     */
    @Query(value = "SELECT * FROM user_task_relation WHERE task_id= ?",
            nativeQuery = true)
    Relation findByRelation(Integer taskId);
}
